package com.example.computer_exam_training_sys.service.impl;

import com.example.computer_exam_training_sys.entity.Question;
import com.example.computer_exam_training_sys.entity.User_Info;
import com.example.computer_exam_training_sys.mapper.User_Info_Mapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.example.computer_exam_training_sys.service.User_Info_Service;

import java.util.List;

@Service
public class User_Info_ServiceImpl implements User_Info_Service {
    @Override
    public PageInfo<User_Info> findAllpage(int pageNo, int pageSize) {
        PageHelper.startPage(pageNo, pageSize);
        List<User_Info> questions = user_Info_Mapper.selectAll();
        return new PageInfo<User_Info>(questions);
    }

    @Autowired
    private User_Info_Mapper user_Info_Mapper;

    @Override
    public List<User_Info> selectAll() {
        return user_Info_Mapper.selectAll();
    }

    @Override
    public User_Info User_InfoselectByID(int user_id) {
        return user_Info_Mapper.User_InfoselectByID(user_id);
    }

    @Override
    public int insertUser(User_Info user) {
        return user_Info_Mapper.insertUser(user);
    }

    @Override
    public int updateUser(User_Info user) {
        return user_Info_Mapper.updateUser(user);
    }

    @Override
    public int deleteUser(int userId) {
        return user_Info_Mapper.deleteUser(userId);
    }

    @Override
    public List<User_Info> getNewUsersToday() {
        return user_Info_Mapper.getNewUsersToday();
    }

    @Override
    public int updateLastLogin(int userId) {
        return user_Info_Mapper.updateLastLogin(userId);
    }

    // ✨ 新增：根据用户名查询用户
    @Override
    public User_Info findByUsername(String username) {
        return user_Info_Mapper.findByUsername(username);
    }

    @Override
    public boolean updatePassword(int userId, String oldPassword, String newPassword) {
        int updated = user_Info_Mapper.updatePassword(userId, oldPassword, newPassword);
        return updated > 0;
    }

    @Override
    public int updateAvatar(int userId, String avatar) {
        return user_Info_Mapper.updateAvatar(userId, avatar);
    }

    @Override
    public int getTotalUserCount() {
        return user_Info_Mapper.getTotalUserCount();
    }
}
